<?php

class Wlib_Translate_Loader
{
    public function loadTranslator($object)
    {
        if(is_object($object)) {
            $className = get_class($object);
        } else if(is_string($object)) {
            $className = $object;
        }

        $separator = '_';
        $classParts = explode($separator, $className);

        $filter = new Zend_Filter_Word_CamelCaseToDash();

        $module = strtolower($filter->filter(array_shift($classParts)));
        $fileName = strtolower($filter->filter(array_pop($classParts))) . '.php';

        $langPath = APPLICATION_PATH . '/modules/' . $module . '/languages/ru/' ;

        foreach ($classParts as $oPart) {
            $langPath .= strtolower($oPart) . '/';
        }

        $langPath .= $fileName;
        $translator = null;
        if(file_exists($langPath)) {
            $translator = new Zend_Translate('array', $langPath);
        }
        return $translator;
    }
}